home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / asmutil / asm_n_z.zip / XALL.ASM < prev    next >
Assembly Source File  |  1990-01-05  |  21KB  |  367 lines

  1.         PAGE   60,132
  2.         TITLE  Xall - High speed eXeute in ALL subdirs utility
  3.         SUBTTL General Program description
  4. ;-----------------------------------------------------------------------------;
  5. ; Xall - eXecute any command in current directory plus all subdirectories     ;
  6. ;-----------------------------------------------------------------------------;
  7. ;    XALL 1.0 ■ PCDATA TOOLKIT Copyright (c) 1990 Ziff Communications Co.     ;
  8. ;                   PC Magazine ■ Wolfgang Stiller                            ;
  9. ;                                                                             ;
  10. ;-----------------------------------------------------------------------------;
  11. ;Purpose:                                                                     ;
  12. ; XALL will eXecute any command in the current directory plus all             ;
  13. ;      subdirectories below that one.  This program is written for high       ;
  14. ;      speed execution (lean and mean!).                                      ;
  15. ;-----------------------------------------------------------------------------;
  16. ;Syntax:                                                                      ;
  17. ;                                                                             ;
  18. ;XALL anyDOScommand                                                           ;
  19. ;                                                                             ;
  20. ;  "anyDOScommand" may be any batch file, program, or DOS command. Any        ;
  21. ;                  programs or batch files should be located in a             ;
  22. ;                  directory specified in the DOS path (PATH=).               ;
  23. ;-----------------------------------------------------------------------------;
  24. ;Remarks:                                                                     ;
  25. ;  "anyDOScommand" will be executed first in the current directory and        ;
  26. ;  then in each subdirectory subordinate to the current directory.  This      ;
  27. ;  program has been optimized for speed and efficiency of execution.  If      ;
  28. ;  execution is terminated, you will be in the directory currently being      ;
  29. ;  processed.  This program does NOT check for execution of other             ;
  30. ;  programs that change the drive or directory. (Speed is the goal!)          ;
  31. ;  XALL has advanced error recovery and provides clear explanations to        ;
  32. ;  PCDATA Toolkit user of what has gone wrong, such as an                     ;
  33. ;  invalid COMSPEC environment variable.                                      ;
  34. ;                                                                             ;
  35. ;  XALL will return the following DOS errorlevels:                            ;
  36. ;                                                                             ;
  37. ;  00 - normal completion                                                     ;
  38. ;  32 - any abnormal occurance - indicates fatal termination.                 ;
  39. ;-----------------------------------------------------------------------------;
  40.  
  41.  
  42. ;-----------------------------------------------------------------;
  43. ; Constants:                                                      ;
  44. ;-----------------------------------------------------------------;
  45. BOX                  EQU  254             ;Small box character code
  46. CR                   EQU  0Dh             ; Carriage return
  47. LF                   EQU  0Ah             ; Line feed
  48. CRLF                 EQU  0A0D            ; CR+LF in one word
  49. First_time           EQU  00h             ; Constant to indicate first time
  50. Not_First_Time       EQU  0FFh            ;             indicate NOT first time
  51. Subdirectory_attrib  EQU  10h             ; Bit pattern to find directories
  52.  
  53. CSEG    SEGMENT
  54.         ASSUME  CS:CSEG, DS:CSEG,ES:CSEG,SS:CSEG
  55.         ORG     2Ch                       ;Segment of environment found here
  56. Environment LABEL BYTE
  57.  
  58.         ORG     7DH                       ;Just before paramter area in PSP
  59. XALL_PARM LABEL  BYTE
  60.  
  61.         ORG     80h                       ;Normal DOS PSP parameter area
  62. PSP_PARM  LABEL  BYTE
  63.  
  64. ;*****************************************************************************
  65. ;** Main program begins here:  XALL - Subdirectory Command eXecuter         **
  66. ;**                            ----                                         **
  67. ;*****************************************************************************
  68.  
  69.         ORG     100h                      ;This is a .COM type program
  70. XALL:
  71.         MOV     SP,OFFSET STACK_TOP       ;Create new stack
  72.  
  73.         MOV     DX,OFFSET XALL_CR_MSG     ;Copyright message
  74.         MOV     AH,09h                    ;DOS print string function
  75.         INT     21h
  76.  
  77.         MOV     BX,offset Program_top     ;End of program + 15 (segment roundng)
  78.         MOV     CX,4                      ;Prepare to div by 4 (calc # of paras)
  79.         SHR     BX,CL                     ;Convert to segment address
  80.         MOV     AH,4Ah                    ;Release uneeded memory
  81.         INT     21h
  82.  
  83.         CALL    Get_COMSPEC               ;Locate the compsec in the environment
  84.         CALL    Create_EXEC_parm_BLOCK    ;Create parameter block for DOS EXEC
  85.         CALL    Create_Command_tail       ;Create /C command for COMMAND.COM
  86.  
  87. ;***********************;
  88. ; MAIN loop begins here ;
  89. ;***********************;
  90. EXEC_Next_Command:                        ;Come here to execute a command
  91.                                           ;in each directory
  92.         CALL    DISPLAY_XALL_MSG          ;Display msg that we are this directry
  93.  
  94. ;---------------------------------------------------------------------------;
  95. ; Use DOS EXEC function to invoke COMMAND.COM with user's specified command ;
  96. ;              tail from the parameter area at 80h.                         ;
  97.         LDS    DX,[Command_Adr]           ;DS:DX is address of command.com str
  98.         MOV    BX,OFFSET Parm_block       ;ES:BX is adr of parameter block
  99.         MOV    AX,4b00h                   ;DOS EXEC sub-task function
  100.         INT    21h                        ;COMMAND.COM now executing user's cmd
  101.  
  102. ; Return from execution of DOS shell - all registers may be corrupted:
  103.         MOV     AX,CS                     ;CS is only OK register
  104.         MOV     ES,AX
  105.         MOV     DS,AX
  106.         MOV     SS,AX
  107.         MOV     SP,OFFSET Stack_top       ;Reset stack pointer
  108.         JC      Handle_Exec_Error         ;If DOS EXEC function failed handle it
  109.  
  110. ;-----------------------------------------------------------------------------;
  111. ;   Now find NEXT (or first) subdirectory below the current one               ;
  112. ;-----------------------------------------------------------------------------;
  113. Find_another_SubDirectory:
  114.         MOV     DX,[DTA_Ptr]              ;Tell DOS to use different DTA
  115.         MOV     AH,1Ah                    ;DOS set DTA function
  116.         INT     21h
  117.  
  118.         CMP     FF_Flag,First_time        ;Is this first time in this directory?
  119.         JNE     Find_next                 ;   IF not, do a find next
  120.         MOV     DX,OFFSET Global_str      ;   Else do an initial find on *.*
  121.         MOV     CX,Subdirectory_attrib    ;       find only subdirectories
  122.         MOV     AH,4Eh                    ;       DOS FIND 1st function
  123.         INT     21h
  124.         JMP     SHORT Validate_directory  ;Skip the FIND NEXT function call
  125.  
  126. Find_Next:                                ;Find the next directory
  127.         MOV     AH,4Fh                    ;DOS find next function
  128.         INT     21h
  129.  
  130. Validate_directory:                       ;Check that we found valid directory
  131.         JC      Return_to_Mother          ;If find failed, Return to  mother dir
  132.         MOV     DI,[DTA_Ptr]              ;Get address of current DTA
  133.  
  134. ;     Check the file attribute bits in the DTA (is it a directory or a file?)
  135.         TEST    BYTE PTR [DI+21],Subdirectory_attrib  ;Is this a directory?
  136.         JE      Find_Next                 ;If its not a directory keep looking
  137.  
  138.         ADD     DI,30                     ;Point to directory name in DTA
  139.         CMP     BYTE PTR [DI],'.'         ;IS it a '.' or '..' dir e